//
//  CmmentCell.m
//  liang ping
//
//  Created by lanou on 16/3/15.
//  Copyright © 2016年 孙金龙. All rights reserved.
//

#import "CmmentCell.h"
#import "UIImageView+WebCache.h"
#import "RequestManager.h"
@implementation CmmentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 15, 100, 45)];
        _nameLabel.font = [UIFont systemFontOfSize:20];
        //_nameLabel.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:_nameLabel];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 65, 100, 25)];
        _timeLabel.font = [UIFont systemFontOfSize:12];
        //_timeLabel.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_timeLabel];
        
        _commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 95, KWidth-30, 50)];
        // _commentLabel.backgroundColor = [UIColor lightGrayColor];
        _commentLabel.numberOfLines = 0;
        _commentLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_commentLabel];
        
        _headButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _headButton.frame = CGRectMake(20, 15, 45, 45);
        // [_headButton setImage:[UIImage imageNamed:@"u43.png"] forState:UIControlStateNormal];
        [_headButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_headButton];
        
        // 给cell添加长按手势
       _longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
        _longPress.enabled = NO;
        [self.contentView addGestureRecognizer:_longPress];
        
        // 给cell添加长按手势
        _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        _tap.enabled = NO;
        [self.contentView addGestureRecognizer:_tap];
        
        _bigView = [[UIView alloc] initWithFrame:CGRectMake(KWidth, 0, 60, 150)];
        [self.contentView addSubview:_bigView];
        
        // 评论别人评论的button
        _commentButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _commentButton.frame = CGRectMake(0, 0, 60, 50);
        [_commentButton setTitle:@"评论" forState:UIControlStateNormal];
        [_commentButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_bigView addSubview:_commentButton];
        
        // 赞别人评论的button
        _supportButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _supportButton.frame = CGRectMake(0, 50, 60, 50);
        [_supportButton setTitle:@"赞" forState:UIControlStateNormal];
        [_supportButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_bigView addSubview:_supportButton];
        
        // 删除自己评论的button
        _deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _deleteButton.frame = CGRectMake(0, 100, 60, 50);
        [_deleteButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        [_bigView addSubview:_deleteButton];
    }
    return self;
}

// 长按手势方法
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateEnded)
    {
        [UIView animateWithDuration:0.1 animations:^{
            _bigView.frame = CGRectMake(KWidth-70, 0, 60, 150);
        } completion:^(BOOL finished) {
            longPress.enabled = NO;
        }];
    }
    
}

// 轻拍手势
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    if (tap.state == UIGestureRecognizerStateEnded)
    {
        [UIView animateWithDuration:0.5 animations:^{
            _bigView.frame = CGRectMake(KWidth, 0, 60, 150);
        }];
        tap.enabled = NO;
    }
}

- (void)setModel:(ProductModel *)model
{
    _timeLabel.text = model.addtime_f;
    _commentLabel.text = model.content;
    _nameLabel.text = model.uname;
    _commentid = model.commentid;

    [_headButton setBackgroundImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.icon]]] forState:UIControlStateNormal];
}


// button 点击事件
- (void)buttonAction:(UIButton *)button
{
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
